Page({
  data: {
    searchValue: '',
    departments: [
      {
        id: 1,
        name: '内科',
        icon: '/assets/svg/neikehuli_1.svg'
      },
      {
        id: 2,
        name: '外科',
        icon: '/assets/svg/putongwaike.svg'
      },
      {
        id: 3,
        name: '儿科',
        icon: '/assets/svg/xinshengerke.svg'
      },
      {
        id: 4,
        name: '妇产科',
        icon: '/assets/svg/chanke_1.svg'
      },
      {
        id: 5,
        name: '眼科',
        icon: '/assets/svg/yanke_1.svg'
      },
      {
        id: 6,
        name: '口腔科',
        icon: '/assets/svg/kouqiangneike.svg'
      },
      {
        id: 7,
        name: '皮肤科',
        icon: '/assets/svg/pifuxingbingke_1.svg'
      },
      {
        id: 8,
        name: '精神科',
        icon: '/assets/svg/jingshenxinlike_1.svg'
      }
    ],
    diseases: [
      { id: 1, name: '感冒发烧' },
      { id: 2, name: '咳嗽' },
      { id: 3, name: '头痛' },
      { id: 4, name: '失眠' },
      { id: 5, name: '胃痛' },
      { id: 6, name: '高血压' },
      { id: 7, name: '糖尿病' },
      { id: 8, name: '关节炎' },
      { id: 9, name: '皮炎' },
      { id: 10, name: '抑郁症' }
    ],
    doctors: [
      {
        id: 1,
        name: '张医生',
        title: '主任医师',
        hospital: '北京协和医院',
        hospitalLevel: '三甲',
        department: '内科',
        specialty: '擅长各种常见内科疾病的诊治，尤其是心血管疾病',
        avatar: 'https://inquiry-xcx.oss-cn-beijing.aliyuncs.com/%E5%8C%BB%E7%94%9F%E5%A4%B4%E5%83%8F.jpg',
        rating: '4.9',
        consultCount: '2000+',
        price: '49'
      },
      {
        id: 2,
        name: '李医生',
        title: '副主任医师',
        hospital: '北京大学第一医院',
        hospitalLevel: '三甲',
        department: '儿科',
        specialty: '小儿常见病、多发病的诊治，儿童保健',
        avatar: 'https://inquiry-xcx.oss-cn-beijing.aliyuncs.com/%E5%8C%BB%E7%94%9F%E5%A4%B4%E5%83%8F.jpg',
        rating: '4.8',
        consultCount: '1500+',
        price: '39'
      },
      {
        id: 3,
        name: '王医生',
        title: '主任医师',
        hospital: '中国医学科学院肿瘤医院',
        hospitalLevel: '三甲',
        department: '外科',
        specialty: '各种常见肿瘤的诊断、手术治疗',
        avatar: 'https://inquiry-xcx.oss-cn-beijing.aliyuncs.com/%E5%8C%BB%E7%94%9F%E5%A4%B4%E5%83%8F.jpg',
        rating: '4.9',
        consultCount: '3000+',
        price: '59'
      }
    ]
  },

  onSearchChange() {
    wx.navigateTo({
      url: '/pages/doctor-search/index',
      fail: (err) => {
        console.error('跳转失败：', err);
        wx.showToast({
          title: '页面跳转失败',
          icon: 'none'
        });
      }
    });
  },

  onExpertTap() {
    wx.showToast({
      title: '权威专家',
      icon: 'none'
    });
  },

  onClinicTap() {
    wx.showToast({
      title: '特惠义诊',
      icon: 'none'
    });
  },

  onDepartmentTap(e) {
    const { id } = e.currentTarget.dataset;
    const department = this.data.departments.find(item => item.id === id);
    if (department) {
      wx.navigateTo({
        url: `/pages/doctor-search/index?departmentId=${id}&departmentName=${encodeURIComponent(department.name)}&type=department`,
        fail: (err) => {
          console.error('跳转失败：', err);
          wx.showToast({
            title: '页面跳转失败',
            icon: 'none'
          });
        }
      });
    }
  },

  onDiseaseTap(e) {
    const { id } = e.currentTarget.dataset;
    const disease = this.data.diseases.find(item => item.id === id);
    if (disease) {
      wx.navigateTo({
        url: `/pages/doctor-search/index?diseaseId=${id}&diseaseName=${encodeURIComponent(disease.name)}&type=disease`,
        fail: (err) => {
          console.error('跳转失败：', err);
          wx.showToast({
            title: '页面跳转失败',
            icon: 'none'
          });
        }
      });
    }
  },

  onDoctorTap(e) {
    const { id } = e.currentTarget.dataset;
    wx.navigateTo({
      url: `/pages/doctor/detail?id=${id}`,
      fail: (err) => {
        console.error('跳转失败：', err);
        wx.showToast({
          title: '页面跳转失败',
          icon: 'none'
        });
      }
    });
  }
}); 